package com.atguigu.eduservice.controller;

import com.atguigu.eduservice.entity.EduComment;
import com.atguigu.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/eduservice/comment")
@Api("课程评论")
public class EduCommentController {
    @Autowired
    EduCommentService commentService;

    /**
     * 增
     */
    @PostMapping("add")
    public String addComment(@RequestBody EduComment eduComment) {
        boolean res = commentService.save(eduComment);
        if (res) {
            return " add success ";
        } else {
            return " add fail ";
        }
    }
    /**
     * 删
     */
    @DeleteMapping("del")
    public String delComment(@RequestParam String id) {
        QueryWrapper<EduComment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        boolean res = commentService.remove(queryWrapper);
        if (res) {
            return " del success";
        } else {
            return " del fail";
        }
    }
    /**
     * 改
     */
    @PutMapping("put")
    public String putComment(@RequestBody EduComment eduComment) {
        boolean res = commentService.updateById(eduComment);
        if (res) {
            return " update success";
        } else {
            return " update fail";
        }
    }
    /**
     * 查
     */
    @GetMapping("get")
    public EduComment getComment(@RequestParam String id) {
        EduComment eduComment = commentService.getById(id);
        return eduComment;
    }
}
